module.exports = function($scope, $modalInstance, $resource, role_list){

    var roles = ',';
    if(role_list.length > 0){
        angular.forEach(role_list, function(item){
            roles += item.value + ',';
        });
    }

    $scope.getRoleList = function(){
        $resource('/api/as/sc/role/getPublicsRoleList', {}, {}).save({}, function(res){
            if (res.errcode === 0) {
                $scope.list = res.data;
                if(roles != ','){
                    angular.forEach($scope.list, function(item){
                        if(roles.indexOf(','+item.id+',') != -1){
                            item.active = true;
                        }
                    });
                }
            }
        });
    }
    $scope.getRoleList();
    
    //确定
    $scope.ok = function () {
        var rte_list = [];
        angular.forEach($scope.list, function(item){
            if(item.active){
                rte_list.push({'name': item.name, 'value': item.id});
            }
        });
        $modalInstance.close(rte_list);
    };

    //取消
    $scope.cancel = function () {
        $modalInstance.dismiss('cancel');
    };

};